package org.hackystat.devcathlon.ui.page.teams.browse;

import static org.junit.Assert.assertNotNull;
import org.apache.wicket.util.tester.FormTester;
import org.apache.wicket.util.tester.WicketTester;
import org.hackystat.devcathlon.engine.test.DevcathlonTestHelper;
import org.hackystat.devcathlon.ui.DevcathlonApplication;
import org.hackystat.devcathlon.ui.page.login.LoginPage;
import org.junit.Test;

/**
 * Test cases for Teams Browse Page.
 * 
 * @author Ka Hung Phillip Lau
 *
 */
public class TestTeamsBrowsePage extends DevcathlonTestHelper {

  private String user = "admin@hackystat.org";
  
  /**
   * Test if the Teams Browse Page will show.
   * 
   * @throws Exception If there is a bug.
   */
  @Test
  public void testTeamsBrowsePage() throws Exception {
    WicketTester tester = new WicketTester(new DevcathlonApplication());
    tester.startPage(TeamsBrowsePage.class);
    tester.assertRenderedPage(LoginPage.class);    
   
    FormTester formTester = tester.newFormTester("loginForm");
    formTester.setValue("user", user);
    formTester.setValue("password", user);
    formTester.submit();
   
    tester.assertRenderedPage(TeamsBrowsePage.class);
    tester.assertLabel("StatusLabel", "Devcathlon have no teams");
    assertNotNull("wicket ID form found.", tester.getTagByWicketId("StatusLabel"));    
    
    makeTeam("Your1stTeam", "admin", "member1", "member2");
    
    tester.clickLink("TeamsBrowseLink");
    tester.assertRenderedPage(TeamsBrowsePage.class);
    
    assertNotNull("wicket ID listview found", tester.getTagByWicketId("TeamsList"));
    assertNotNull("wicket ID Memberlistview found", tester.getTagByWicketId("MembersList"));
    
    deleteTeam("Your1stTeam");
    
  }
}
